<?php


// 接受参数
$dep_id = isset($_GET['dep_id']) ? $_GET['dep_id'] : null;

if ($dep_id){

    require_once('./dbfunc.php');
    require_once('./dbparam.php');

    header('Content-Type: json');

    // 连接数据库
    $conn = conn_mysql();

    $sql = "
    select cl_id, cl_name 
    from huangcz_class, huangcz_major
    where cl_major = ma_id
    and ma_dep = ?;
    ";

    // 结果参数
    $cl_id = 0;
    $cl_name = '';

    $stmt = $conn->prepare($sql);
    $stmt->bind_param('i', $dep_id);
    $stmt->bind_result($cl_id, $cl_name);
    $stmt->execute();

    $response = [];

    while ($stmt->fetch()){
        $response[] = [
            'cl_id' => $cl_id,
            'cl_name' => $cl_name
        ];
    }

    exit(json_encode($response, JSON_UNESCAPED_UNICODE));

}else{
    exit(json_encode([]));
}
